Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand VersoView to include more APIs #275

Open
wants to merge 33 commits into
base: main
Choose a base branch
from

Conversation

Legend-Master
Copy link
Contributor

@Legend-Master Legend-Master commented Feb 12, 2025

Added control APIs:

  • exit
  • execute_script
  • set_size
  • set_position
  • set_maximized
  • set_minimized
  • set_fullscreen
  • set_visible
  • get_size
  • get_position
  • is_maximized
  • is_minimized
  • is_fullscreen
  • is_visible
  • get_scale_factor
  • get_current_url
  • start_dragging

Added init settings:

  • size
  • position
  • maximized
  • resources_directory
  • userscripts_directory
  • devtools_port

Other APIs:

  • on_web_resource_requested
  • on_close_requested

@Legend-Master Legend-Master mentioned this pull request Feb 12, 2025
14 tasks
@Legend-Master Legend-Master marked this pull request as ready for review February 13, 2025 05:46
@Legend-Master Legend-Master mentioned this pull request Feb 13, 2025
17 tasks
Copy link
Contributor Author

@Legend-Master Legend-Master left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To help with the review process, have left a few remarks

src/config.rs Show resolved Hide resolved
src/verso.rs Outdated
Comment on lines 455 to 477
if let Some((window, _)) = self.windows.get_mut(&window_id) {
if let WindowEvent::CloseRequested = event {
if let Some(to_controller_sender) = &self.to_controller_sender {
if window.event_listeners.on_close_requested {
if let Err(error) =
to_controller_sender.send(ToControllerMessage::OnCloseRequested)
{
log::error!("Verso failed to send WebResourceRequested to controller: {error}")
} else {
return false;
}
}
}
// self.windows.remove(&window_id);
compositor.maybe_start_shutting_down();
} else {
window.handle_winit_window_event(
&self.constellation_sender,
compositor,
&event,
);
return window.resizing;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the controller said they want to handle the CloseRequested event, send it to the controller instead of handling it ourselves

src/verso.rs Show resolved Hide resolved
Comment on lines +344 to +353
pub fn get_size(&self) -> Result<PhysicalSize<u32>, Box<ipc_channel::ErrorKind>> {
self.sender.send(ToVersoMessage::GetSize)?;
let (sender, receiver) = std::sync::mpsc::channel();
self.event_listeners
.size_response
.lock()
.unwrap()
.replace(sender);
Ok(receiver.recv().unwrap())
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Things like these work like this:

  1. we send ToVersoMessage::GetSize here, and wait with a blocking receive
  2. versoview receives this message and push send us back a ToControllerMessage::GetSizeResponse
  3. We receive this message from the message look created in the beginning
  4. Our message look send the message to us
  5. We receive this message and return it to the caller

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we ensure ToControllerMessage::GetSizeResponse will be sent after the size_response is set? Since they are running in different process.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes and no, we can ensure it's always sent in normal cases but if the other side crashed or something when wrong during the IPC calls this will go wrong, but I don't think we can do much about those cases anyways

Copy link
Collaborator

@pewsheen pewsheen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left some comments. Btw, do we have examples to test these functions?

src/verso.rs Outdated Show resolved Hide resolved
_ => {}
}
}

fn first_webview_id(&self) -> Option<TopLevelBrowsingContextId> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since ToVersoMessage uses many of the first available Window, maybe we can add a first_window here and a current_tab_id method in Window.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, are we sure there can be only one Window in this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since ToVersoMessage uses many of the first available Window, maybe we can add a first_window here and a current_tab_id method in Window.

Yeah, I could add one

Also, are we sure there can be only one Window in this case?

Yes

}
ToVersoMessage::GetSize => {
if let Some((window, _)) = self.windows.values_mut().next() {
if let Err(error) = self.to_controller_sender.as_ref().unwrap().send(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we handle the unwrap?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to_controller_sender should always present as this function is only called when we received messages from the other side, I can put it in the beginning of this function though

src/verso.rs Outdated Show resolved Hide resolved
src/webview/webview.rs Outdated Show resolved Hide resolved
verso/src/lib.rs Outdated Show resolved Hide resolved
verso/src/lib.rs Outdated Show resolved Hide resolved
verso/src/lib.rs Outdated Show resolved Hide resolved
Comment on lines +344 to +353
pub fn get_size(&self) -> Result<PhysicalSize<u32>, Box<ipc_channel::ErrorKind>> {
self.sender.send(ToVersoMessage::GetSize)?;
let (sender, receiver) = std::sync::mpsc::channel();
self.event_listeners
.size_response
.lock()
.unwrap()
.replace(sender);
Ok(receiver.recv().unwrap())
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we ensure ToControllerMessage::GetSizeResponse will be sent after the size_response is set? Since they are running in different process.

// and send ConstellationMsg::AllowNavigationResponse there if the call succeed
return;
}
}
}
send_to_constellation(sender, ConstellationMsg::AllowNavigationResponse(id, true));
}
EmbedderMsg::WebResourceRequested(_webview_id, request, sender) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering if we should add a feature flag in the future as this kind of logic growing up will increasing maintenance effort.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might be hard to keep everything related to the webview controllers in a feature flag as it's quite integrated, but we could try that in a future PR

@Legend-Master
Copy link
Contributor Author

do we have examples to test these functions?

I do have some examples in the https://github.com/versotile-org/tauri-runtime-verso repo but not here though, for a quick test you should be able to use those function in verso/src/main.rs fairly easily like https://github.com/Legend-Master/verso/blob/ebf0210541254f6141ce2eae69831f96e7e06945/verso/src/main.rs#L16-L21

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants